import {createRouter, createWebHistory} from 'vue-router'
import HomeView from '../views/HomeView.vue'
import menus from './menu'

const router = createRouter({
    history: createWebHistory(import.meta.env.BASE_URL),
    routes: [
        // 基础路由
        {
            path:"/",
            redirect:"/homePage"
        },
        {
            path: '/homePage',
            name: 'homePage',
            component: () => import('@/views/HomePage.vue')
        },
        {
        path: '/productDetails/:pid',
        name: 'productDetails',
        component: () => import('../views/product/ProductDetails.vue'),
        },
        {
        path: '/shopHome/:shopId?/:categoryId?',
        name: 'shopHome',
        component: () => import('../views/product/ShopHomePage.vue'),
        },
        {
        path: '/download/:productId/',
        name: 'download',
        component: () => import('../views/product/Download.vue'),
        },
         {
            path: '/login',
            name: 'login',
            component: () => import('../views/Login.vue')
        },
        {
            path: '/register',
            name: 'register',
            component: () => import('../views/register/Register.vue'),
            children:[
               { path: 'step1',
                name: 'step1',
                component: () => import('../views/register/RType.vue')
               },
               { path: 'wx',
                name: 'wxRegister',
                component: () => import('../views/register/WxRegister.vue')
               },
               { path: 'sy',
                name: 'syRegister',
                component: () => import('../views/register/SyRegister.vue')
               }
            ]
        },
        {
            path: '/home',
            name: 'home',
            component: HomeView,
            children:menus
            
        },
        
    ]
})
router.beforeEach((to, from, next) => {
    console.log('路由前置导航守卫==', to, from)
    if(to.path === '/dashboard' ){
        document.title = "易购网卖家管理中心"
    }
    next()

})


export default router
